﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Maticsoft.DBUtility;

namespace EnterpriseFund.DAL
{
    /// <summary>
    /// 数据访问类:HRDept
    /// </summary>
    public partial class HRDept
    {
        public HRDept()
        { }
        #region  BasicMethod

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.HRDept GetModel(string FEntityNo, string FDeptNo)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FEntityNo,FDeptNo,FDeptName,FIsAgency,FDeptProp,FSeq,FChargeLeader,FParentDeptNo,FIsEval from t_HRDept ");
            strSql.Append(" where FEntityNo=@FEntityNo and FDeptNo=@FDeptNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FDeptNo", SqlDbType.NVarChar,12)			};
            parameters[0].Value = FEntityNo;
            parameters[1].Value = FDeptNo;

            Model.HRDept model = new Model.HRDept();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.HRDept DataRowToModel(DataRow row)
        {
            Model.HRDept model = new Model.HRDept();
            if (row != null)
            {
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                if (row["FDeptNo"] != null)
                {
                    model.FDeptNo = row["FDeptNo"].ToString();
                }
                if (row["FDeptName"] != null)
                {
                    model.FDeptName = row["FDeptName"].ToString();
                }
                if (row["FIsAgency"] != null)
                {
                    model.FIsAgency = row["FIsAgency"].ToString();
                }
                if (row["FDeptProp"] != null)
                {
                    model.FDeptProp = row["FDeptProp"].ToString();
                }
                if (row["FSeq"] != null && row["FSeq"].ToString() != "")
                {
                    model.FSeq = int.Parse(row["FSeq"].ToString());
                }
                if (row["FChargeLeader"] != null)
                {
                    model.FChargeLeader = row["FChargeLeader"].ToString();
                }
                if (row["FParentDeptNo"] != null)
                {
                    model.FParentDeptNo = row["FParentDeptNo"].ToString();
                }
                if (row["FIsEval"] != null)
                {
                    model.FIsEval = row["FIsEval"].ToString();
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FEntityNo,FDeptNo,FDeptName,FIsAgency,FDeptProp,FSeq,FChargeLeader,FParentDeptNo,FIsEval ");
            strSql.Append(" FROM t_HRDept ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" FEntityNo,FDeptNo,FDeptName,FIsAgency,FDeptProp,FSeq,FChargeLeader,FParentDeptNo,FIsEval ");
            strSql.Append(" FROM t_HRDept ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }



        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}
